/*
 * *****************************************************************************
 *  Copyright ( c ) 2019 huibur Inc. All Rights Reserved.
 *
 *  This software is the confidential and proprietary information of Huibur Inc
 *  (*Confidential Information*). You shall not disclose such Confidential Information
 *  and shall use it only in accordance with the terms of the license agreement
 *  you entered into with Huibur or a Huibur authorized
 *  reseller (the "License Agreement*).
 *  ******************************************************************************
 */

package com.huibur.devicecheck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.huibur.devicecheck.exception.ParameterSettingErrorException;
import com.huibur.devicecheck.exception.RemindTimeSettingErrorException;
import com.huibur.devicecheck.mapper.SysParamsMapper;
import com.huibur.devicecheck.model.param.DeviceParam;
import com.huibur.devicecheck.model.param.SysParamsParam;
import com.huibur.devicecheck.model.po.DevicePO;
import com.huibur.devicecheck.model.po.SysParamsPO;
import com.huibur.devicecheck.request.ObjRes;
import com.huibur.devicecheck.request.SessionContext;
import com.huibur.devicecheck.service.ISysParamsService;
import com.huibur.devicecheck.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/*******************************************************
* Title: SysParamsServiceImpl.java
* Description:
* @author baiqingshuo
* @date 2021/10/12
* @version 1.0
*******************************************************/
@Service
public class SysParamsServiceImpl implements ISysParamsService {
    @Autowired
    SysParamsMapper sysParamsMapper;

    /**
     * 编辑参数设置
     * @param
     * @param sysParamsParam
     * @return
     */
    @Override
    public ObjRes<Void> updateSysParams(SysParamsParam sysParamsParam) {
        if (1 > sysParamsParam.getCheckDay() || 32 <= sysParamsParam.getCheckDay()) {
            throw new ParameterSettingErrorException();
        }
        if (0 >= sysParamsParam.getRemindDay() || sysParamsParam.getCheckDay() <= sysParamsParam.getRemindDay()) {
            throw new RemindTimeSettingErrorException();
        }
        SysParamsPO sysParamsPO = new SysParamsPO();
        sysParamsPO.setId(1L);
        sysParamsPO.setCheckDay(sysParamsParam.getCheckDay());
        sysParamsPO.setRemindDay(sysParamsParam.getRemindDay());
        sysParamsMapper.updateById(sysParamsPO);
            return new ObjRes<Void>().success("修改成功");
    }

    /**
     * 获取系统参数设置
     * @return
     */
    @Override
    public SysParamsPO selectData() {
        SysParamsPO sysParams = sysParamsMapper.selectOne(new LambdaQueryWrapper<SysParamsPO>()
                .eq(SysParamsPO::getId, 1));
        SysParamsPO sysParamsPO = new SysParamsPO();
        sysParamsPO.setId(sysParams.getId());
        sysParamsPO.setCheckDay(sysParams.getCheckDay());
        sysParamsPO.setRemindDay(sysParams.getRemindDay());
        return sysParamsPO;
    }
}
